Plotting data is fun. We also do it for data exploration (see the section on Exploratory Data Analysis). Still, at least in this slot of exercise, we just want to familiarize ourselves with some of the graphic facilities in R.
So let’s start with a simple task: creating a simple scatter plot. For this purpose, we first load the GESIS Panel COVID-19 survey data.
library(dplyr)
library(haven)
gp_covid <-
read_sav(
"../data/ZA5667_v1-1-0.sav"
) %>%
sjlabelled::set_na(na = c(-1:-99, 97))
Now let’s plot an actual variable from the dataset.
political_orientation and hzcy001a.
jitter().
Who doesn’t like some colors, right? This exercise is not for a print journal with ridiculous fees for beautiful colorful plots. Let’s use that to our advantage.
ColourPicker add-in for more modern colors?
These scatter plots can get boring. So how about some bar plots? However, creating only one bar plot is also not that exciting. Luckily, we can do more and plot more than one.
par() function in combination with its mfrow option.
That’s interesting. One may wonder what the median is in each of these distributions. You know what’s perfect for visualizing this statistic? Boxplots!
boxplot().
Before we later start with the other exercises, you may want to consider to clean your graphics device with dev.off()
dev.off()
## null device
## 1